package com.java.service.impl;

import com.java.entity.QuestionType;
import com.java.mapper.QuestionTypeMapper;
import com.java.service.QuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class QuestionTypeServiceImpl implements QuestionTypeService {

    @Autowired
    private QuestionTypeMapper questionTypeMapper;

    @Override
    public int insert(QuestionType questionType) {
        return questionTypeMapper.insertSelective(questionType);
    }

    @Override
    public int delete(Integer questionTypeId) {
        return questionTypeMapper.deleteByPrimaryKey(questionTypeId);
    }

    @Override
    public int update(QuestionType questionType) {
        return questionTypeMapper.updateByPrimaryKeySelective(questionType);
    }

    @Override
    public QuestionType selectOne(Integer questionTypeId) {
        QuestionType questionType = questionTypeMapper.selectByPrimaryKey(questionTypeId);
        if (questionType == null) {
            throw new RuntimeException("questionType is null, questionTypeId=" + questionTypeId);
        }
        return questionType;
    }

    @Override
    public List<QuestionType> selectAll() {
        return questionTypeMapper.selectByExample(null);
    }

}
